package xyz.zhangyi.onjava.java8.example.lambda.designpattern.bridge;

import xyz.zhangyi.onjava.java8.example.lambda.designpattern.bridge.entity.Customer;
import xyz.zhangyi.onjava.java8.example.lambda.designpattern.bridge.entity.Training;

import java.sql.*;
import java.util.List;

public class TrainingService {
    private final TransactionScope transactionScope;

    public TrainingService(TransactionScope ts) {
        transactionScope = ts;
    }

    public void subscribe(List<Training> trainings, Customer customer) throws SQLException {
        transactionScope.using(new Command() {
            @Override
            public void execute() {
                for (Training training : trainings) {
                    addTrainingItem(customer, training);
                }
                addOrder(customer, trainings);
            }
        });
    }

    private void addOrder(Customer customer, List<Training> trainings) {
    }

    private void addTrainingItem(Customer customer, Training training) {
    }
}
